/**
 * Sep 5, 2012 5:54:22 AM
 * com.kratonsolution.cbs.common
 * Paging.java
 */
package com.kratonsolution.belian.common.util;

/**
 * @author Agung Dodi Perdana
 * @email agung.dodi.perdana@gmail.com
 * @Version Sinch 0.0.1
 */
public class Paging
{
    public static final int start(int page,int rowPerPage)
    {
        if(page > 0)
            return (page-1)*rowPerPage;
        
        return 0;
    }
    
    public static final long totalPage(int totalRow,int rowPerPage)
    {
        if(totalRow > rowPerPage)
        {
            if((totalRow % rowPerPage) == 0L)
                return (totalRow/rowPerPage);
            else
                return (totalRow/rowPerPage)+1;
        }
        
        return 1L;
    }
    
    public static final int defStart()
    {
        return 0;
    }
    
    public static final int defRowPerPage()
    {
        return 20;
    }
    
    public static final synchronized int getStart(Object object)
    {
        if(object == null || !(object instanceof Integer))
            return Paging.defStart();
        
        return Numbers.getIntOrZero(object);
    }
    
    public static final synchronized int getRowPerPage(Object object)
    {
        if(object == null || !(object instanceof Integer))
            return Paging.defRowPerPage();
        
        return Numbers.getInt(object,Paging.defRowPerPage());
    }
}
